﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WineStore.DAL;
using WineStore.Models;

namespace WineStore.Controllers
{
    public class PartialViewController : Controller
    {
        //
        // GET: /PartialLogo/

        [ChildActionOnly]
        public ActionResult PartialLogo()
        {
            ViewBag.Logo = null;
            try
            {
                using (WineDbContext db = new WineDbContext())
                {
                    ViewBag.Logo = db.Logo.FirstOrDefault();
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View();
        }

        //
        // GET: /PartialSupplier/

        [ChildActionOnly]
        public ActionResult PartialSupplier()
        {
            ViewBag.Supplier = null;
            try
            {
                using (WineDbContext db = new WineDbContext())
                {
                    ViewBag.Supplier = db.Suppliers.OrderBy(s => s.DisplayOrder).ToList();
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View();
        }

        //
        // GET: /PartialCategorySim/

        [ChildActionOnly]
        public ActionResult PartialCategorySim()
        {
            ViewBag.Category = null;
            try
            {
                using (WineDbContext db = new WineDbContext())
                {
                    ViewBag.Category = db.CategorySims.OrderBy(s => s.DisplayOrder).ToList();
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View();
        }

        //
        // GET: /PartialPhongThuySim/

        [ChildActionOnly]
        public ActionResult PartialPhongThuySim()
        {
            return View();
        }

        //
        // GET: /PartialCountSim/

        [ChildActionOnly]
        public ActionResult PartialCountSim()
        {
            ViewBag.Count = null;
            try
            {
                using (WineDbContext db = new WineDbContext())
                {
                    ViewBag.Count = (from s in db.Sims
                                     where s.SupplierId != null
                                     group s by new { s.SupplierId, s.Supplier.SupplierName } into resultsSet
                                     orderby resultsSet.Key.SupplierId
                                     select new CountSimModel
                                     {
                                         Key = resultsSet.Key.SupplierId,
                                         SupplierName = resultsSet.Key.SupplierName,
                                         Count = resultsSet.Count()
                                     }
                                 ).ToList();
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View();
        }

        //
        // GET: /PartialFanpageFacebook/

        [ChildActionOnly]
        public ActionResult PartialFanpageFacebook()
        {
            return View();
        }

        //
        // GET: /PartialSearchNumber/

        [ChildActionOnly]
        public ActionResult PartialSearchNumber()
        {
            return View();
        }

        //
        // GET: /PartialNews/

        [ChildActionOnly]
        public ActionResult PartialNews()
        {
            ViewBag.News = null;
            try
            {
                using (WineDbContext db = new WineDbContext())
                {
                    ViewBag.News = db.News.OrderByDescending(n => n.NewsId).ToList();
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View();
        }

        //
        // GET: /PartialLinkWebsite/

        [ChildActionOnly]
        public ActionResult PartialLinkWebsite()
        {
            ViewBag.LinkWebsites = null;
            try
            {
                using (WineDbContext db = new WineDbContext())
                {
                    ViewBag.LinkWebsites = db.LinkWebsites.OrderByDescending(l => l.LinkWebsiteId).ToList();
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View();
        }

        //
        // GET: /PartialSearchByNumber/

        [ChildActionOnly]
        public ActionResult PartialSearchByNumber()
        {
           
            return View();
        }

    }
}
